<!DOCTYPE html>
<head>
   
</head>
<body></body>
<script src="pixi.js"></script>
<script>
    class Game{
constructor(){
    let g={
        stage:0,
        actions:{},
        stage_sign:{
         Loading:0,
         MainUI:1,
        },
        fps:60,
        keydowns:{}
    }
        Object.assign(this, g)
    }
    static new () {
    let g = new this()
    g.init()
    return g
  }
    init(){
        let g = this,
        _main = window._main

    // 设置键盘按下及松开相关注册函数
    window.addEventListener('keydown', function (event) {
      g.keydowns[event.keyCode] = 'down'
    })
    window.addEventListener('keyup', function (event) {
      g.keydowns[event.keyCode] = 'up'
    })
    g.registerAction = function (key, callback) {
      g.actions[key] = callback
    }
    // 设置轮询定时器
    g.timer = setInterval(function () {
    
    }, 1000/g.fps)
  let app = new PIXI.Application({ width: 640, height: 360 });
  document.body.appendChild(app.view);

  // Create the sprite and add it to the stage
  let sprite = PIXI.Sprite.from('images/background1.png');
  app.stage.addChild(sprite);

  // Add a ticker callback to move the sprite back and forth
  let elapsed = 0.0;
  app.ticker.add((delta) => {
    elapsed += delta;
    sprite.x = 100.0 + Math.cos(elapsed/50.0) * 100.0;
  });
}
}
game= Game.new()
</script>
<style>
    *{
        margin:0;
    }
</style>